/*

HardwareProfile.h

Hardware profile for Explorer 16 board for use with 
MRF24J40RadioDemoPic24

*/

#ifndef _ELWIREHARDWARE_
    #define _ELWIREHARDWARE_
    #include "Compiler.h"
    #include <PIC24F_plib.h>
    #include "GenericTypeDefs.h"
    #include "timer.h"


    /*******************************************************************/
    /******** USB stack hardware selection options *********************/
    /*******************************************************************/
    //This section is the set of definitions required by the MCHPFSUSB
    //  framework.  These definitions tell the firmware what mode it is
    //  running in, and where it can find the results to some information
    //  that the stack needs.
    //These definitions are required by every application developed with
    //  this revision of the MCHPFSUSB framework.  Please review each
    //  option carefully and determine which options are desired/required
    //  for your application.

    //#define USE_SELF_POWER_SENSE_IO
    #define tris_self_power     TRISAbits.TRISA2    // Input
    #define self_power          1

    //#define USE_USB_BUS_SENSE_IO
    #define tris_usb_bus_sense  U1OTGSTATbits.SESVD   //TRISBbits.TRISB5    // Input
    #define USB_BUS_SENSE       U1OTGSTATbits.SESVD

    //Uncomment this to make the output HEX of this project
    //   to be able to be bootloaded using the HID bootloader
    //#define PROGRAMMABLE_WITH_USB_HID_BOOTLOADER

    //If the application is going to be used with the HID bootloader
    //  then this will provide a function for the application to
    //  enter the bootloader from the application (optional)
    #if defined(PROGRAMMABLE_WITH_USB_HID_BOOTLOADER)
        #define EnterBootloader() __asm__("goto 0x400")
    #endif

    /*******************************************************************/
    /******** Radio  ***************************************************/
    /*******************************************************************/
    // Set hardware interface pins to use.
    // If a PIC with Peripheral Pin Select is used, also make sure to set up
    // Peripheral Pin Select registers to the correct pins (Interrupt pin and SPI pins if HW SPI is uses).
    // This setting is for the Explorer 16 development board

    #define RADIO_INT_PIN           PORTFbits.RF4
    #define RADIO_INT_TRIS          TRISFbits.TRISF4
    #define RADIO_IF                IFS1bits.INT1IF
    #define RADIO_IE                IEC1bits.INT1IE
    #define RADIO_INTPOL            INTCON2bits.INT1EP

    #define RADIO_CS                LATDbits.LATD14
    #define RADIO_CS_TRIS           TRISDbits.TRISD14
    #define RADIO_RESETn            LATFbits.LATF8
    #define RADIO_RESETn_TRIS       TRISFbits.TRISF8
    #define RADIO_WAKE              LATDbits.LATD15
    #define RADIO_WAKE_TRIS         TRISDbits.TRISD15

    // SDI = SPI_MISO
    #define RADIO_SPI_SDI           PORTBbits.RB15
    #define RADIO_SDI_TRIS          TRISBbits.TRISB15
    // SDO = SPI_MOSI
    #define RADIO_SPI_SDO           LATFbits.LATF5
    #define RADIO_SDO_TRIS          TRISFbits.TRISF5


    #define RADIO_SPI_SCK           LATFbits.LATF2
    #define RADIO_SCK_TRIS          TRISFbits.TRISF2


    #define SPICON1                 SPI1CON1
    #define SPISTAT                 SPI1STAT
    #define SPIBUF                  SPI1BUF
    #define SPI_IF                  IFS0bits.SPI1IF
    #define SPICON1_VAL             ((0b0000000100100000) | (SPI_CLKFREQ & 0x1F))
    #define SPISTAT_VAL             (0x8000)
    #define SPI_CLKFREQ             (0x1e)					// Lowest 4 bits of SPICON1 that sets SPI clock speed
                                                                                // 0x1e = FCY/4
    // If using a PIC with reconfigurable I/O (Peripheral Pin Select) also make sure
    // to set up Peripheral Pin Select Registers to the correct pin.
    /*******************************************************************/
    /*******************************************************************/
    /*******************************************************************/
    /******** Application specific definitions *************************/
    /*******************************************************************/
    /*******************************************************************/
    /*******************************************************************/

    /** Board definition ***********************************************/
    //These defintions will tell the main() function which board is
    //  currently selected.  This will allow the application to add
    //  the correct configuration bits as wells use the correct
    //  initialization functions for the board.  These defitions are only
    //  required in the stack provided demos.  They are not required in
    //  final application design.
    
    
    #define CLOCK_FREQ      8000000
    #define TMR1_PERIOD     1024        // 250us at 8MHz

    /** I/O pin definitions ********************************************/
    #define INPUT_PIN 1
    #define OUTPUT_PIN 0

    /** LED ************************************************************/
    #define LED_GREEN           LATAbits.LATA14
    #define LED_BLUE            LATDbits.LATD8
    
    #define InitAllLEDs()       LED_GREEN = 0; TRISAbits.TRISA14 = OUTPUT_PIN; LED_BLUE = 0; TRISDbits.TRISD8 = OUTPUT_PIN;

    #define GetLED_GREEN()      LED_GREEN
    #define GetLED_BLUE()       LED_BLUE

    #define LED_GREEN_On()      LED_GREEN = 1;
    #define LED_BLUE_On()       LED_BLUE = 1;

    #define LED_GREEN_Off()     LED_GREEN = 0;
    #define LED_BLUE_Off()      LED_BLUE = 0;

    #define LED_GREEN_Toggle()  LED_GREEN = !LED_GREEN;
    #define LED_BLUE_Toggle()   LED_BLUE = !LED_BLUE;

    /** Push Button ***********************************************************/
    #define PUSH_BUTTON         PORTBbits.RB3
    #define PUSH_BUTTON_TRIS    TRISBbits.TRISB3

    // Following definition is for delay functionality
    #define GetInstructionClock()   (CLOCK_FREQ/2)

    extern void hardwareprofile_Init(void);
    extern UINT16 hardwareprofile_GetBoardAddr(void);
    
#endif

